package com.example.student.service.Impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.common.constants.RdsConstants;
import com.example.common.domain.pojo.Teacher;
import com.example.common.utils.CacheClient;
import com.example.student.mapper.TeacherMapper;
import com.example.student.service.TeacherService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.concurrent.TimeUnit;

@Service
public class TeacherServiceImpl extends ServiceImpl<TeacherMapper, Teacher> implements TeacherService {
    @Autowired
    private CacheClient cacheClient;

    @Override
    public Teacher getTeacherByIdWithLogicalExpire(String id) {
        System.out.println(RdsConstants.TEACHER_INFO + id);
        // 使用逻辑过期策略获取教师信息
        return cacheClient.queryWithLogicalExpire(
                RdsConstants.TEACHER_INFO,
                id,
                Teacher.class,
                this::getById, // 使用MyBatis-Plus的基础方法
                RdsConstants.CACHE_NULL_TTL,
                TimeUnit.MINUTES,
                false
        );
    }

}
